﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using MobileSales.Model.Util;
using System.ComponentModel.DataAnnotations;
using MobileSales.Model.Localization;

namespace MobileSales.Model.Tasks
{
    [DataContract]
    public abstract class TaskBase
    {
        #region Public members
        [DataMember(Name = "CreationDate")]
        private string _creationDate { get; set; }
        [Display(Name = "CreationDate", ResourceType = typeof(ModelStrings))]
        public DateTime CreationDate
        {
            get
            {
                if (_creationDate != null) return DateUtil.Deserialize(_creationDate);
                return DateTime.MinValue;
            }
            set
            {
                _creationDate = DateUtil.Serialize(value);
            }
        }
        [DataMember(Name = "ModificationDate")]
        private string _modificationDate { get; set; }
        [Display(Name = "ModificationDate", ResourceType = typeof(ModelStrings))]
        public DateTime ModificationDate
        {
            get
            {
                if (_modificationDate != null) return DateUtil.Deserialize(_modificationDate);
                return DateTime.MinValue;
            }
            set
            {
                _modificationDate = DateUtil.Serialize(value);
            }
        }
        [DataMember(Name="StartTime")]
        private string _startTime { get; set; }
        [Display(Name = "StartTime", ResourceType = typeof(ModelStrings))]
        public DateTime StartTime
        {
            get
            {
                if (_startTime != null) return DateUtil.Deserialize(_startTime);
                return DateTime.MinValue;
            }
            set
            {
                _startTime = DateUtil.Serialize(value);
            }
        }
        [DataMember(Name = "EndTime")]
        private string _endTime { get; set; }
        [Display(Name = "EndTime", ResourceType = typeof(ModelStrings))]
        public DateTime EndTime
        {
            get
            {
                if (_endTime != null) return DateUtil.Deserialize(_endTime);
                return DateTime.MinValue;
            }
            set
            {
                _endTime = DateUtil.Serialize(value);
            }
        }
        [DataMember(Name = "RealStartTime")]
        private string _realStartTime { get; set; }
        [Display(Name = "RealStartTime", ResourceType = typeof(ModelStrings))]
        public DateTime? RealStartTime
        {
            get
            {
                if (_realStartTime != null) return DateUtil.Deserialize(_realStartTime);
                return null;
            }
            set
            {
                if (value.HasValue) _realStartTime = DateUtil.Serialize(value.Value);
                else _realStartTime = null;
            }
        }
        [DataMember(Name = "RealEndTime")]
        private string _realEndTime { get; set; }
        [Display(Name = "RealEndTime", ResourceType = typeof(ModelStrings))]
        public DateTime? RealEndTime
        {
            get
            {
                if (_realEndTime != null) return DateUtil.Deserialize(_realEndTime);
                return null;
            }
            set
            {
                if (value.HasValue) _realEndTime = DateUtil.Serialize(value.Value);
                else _realEndTime = null;
            }
        }
        [DataMember]
        [Display(Name = "StartPositionLatitude", ResourceType = typeof(ModelStrings))]
        public double? StartPositionLatitude { get; set; }
        [DataMember]
        [Display(Name = "StartPositionLongitude", ResourceType = typeof(ModelStrings))]
        public double? StartPositionLongitude { get; set; }
        [DataMember]
        [Display(Name = "EndPositionLatitude", ResourceType = typeof(ModelStrings))]
        public double? EndPositionLatitude { get; set; }
        [DataMember]
        [Display(Name = "EndPositionLongitude", ResourceType = typeof(ModelStrings))]
        public double? EndPositionLongitude { get; set; } 
        #endregion
    }
}
